<?php

use app\models\Options;
use app\models\Project;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;

/** @var yii\web\View $this */
/** @var app\models\SearchProject $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */

$this->title = Yii::t('app', 'Project');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="project-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a(Yii::t('app', 'Create'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        // 'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'name',
            [
                'label' => Yii::t('app', 'All Issues'),
                'format' => 'raw',
                'value' => function(Project $model){
                    return Html::a($model->getIssues()->count(), ['issue/of-project', 'projectId' => $model->id]);
                }
            ],
            [
                'label' => Yii::t('app', 'Collected Issues'),
                'format' => 'raw',
                'value' => function(Project $model){
                    return Html::a($model->getCollectedIssues()->count(), ['issue/of-project', 'projectId' => $model->id, 'state' => Options::IssueCollected]);
                }
            ],
            [
                'label' => Yii::t('app', 'Working Issues'),
                'format' => 'raw',
                'value' => function(Project $model){
                    return Html::a($model->getWorkingIssues()->count(), ['issue/of-project', 'projectId' => $model->id, 'state' => Options::IssueWorking]);
                }
            ], 
            [
                'label' => Yii::t('app', 'Finished Issues'),
                'format' => 'raw',
                'value' => function(Project $model){
                    return Html::a($model->getWorkingIssues()->count(), ['issue/of-project', 'projectId' => $model->id, 'state' => Options::IssueFinished]);
                }
            ], 
            'state:projectState',
            'createdAt:date',
            'updatedAt:relativeTime',
            [
                'class' => ActionColumn::class,
                'urlCreator' => function ($action, Project $model, $key, $index, $column) {
                    return Url::toRoute([$action, 'id' => $model->id]);
                 }
            ],
        ],
    ]); ?>


</div>
